﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using SYDZ.WMS.DBUtility;
namespace WMSAML.Warehouse.DAL
{
	public partial class T_PickStockPrepare
	{
		public T_PickStockPrepare()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(WMSAML.Warehouse.Model.T_PickStockPrepare model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_PickStockPrepare(");
			strSql.Append("PutList_NO,OutList_NO,PickList_NO,BanHao,List_NOType,Posiont1,Posiont2,Product_Model,Serial_Number,Product_Weight,Create_Time,Update_Time,Update_UserID,RuKu_Time1,RuKu_Time2,BK01,BK02,BK03,BK04,BK05,BK06,BK07,BK08,BK09,BK10,BK11,BK12,BK13,BK14,BK15,BK16,BK17,BK18,BK19,BK20)");
			strSql.Append(" values (");
			strSql.Append("@PutList_NO,@OutList_NO,@PickList_NO,@BanHao,@List_NOType,@Posiont1,@Posiont2,@Product_Model,@Serial_Number,@Product_Weight,@Create_Time,@Update_Time,@Update_UserID,@RuKu_Time1,@RuKu_Time2,@BK01,@BK02,@BK03,@BK04,@BK05,@BK06,@BK07,@BK08,@BK09,@BK10,@BK11,@BK12,@BK13,@BK14,@BK15,@BK16,@BK17,@BK18,@BK19,@BK20)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@PutList_NO", SqlDbType.NVarChar,200),
					new SqlParameter("@OutList_NO", SqlDbType.NVarChar,200),
					new SqlParameter("@PickList_NO", SqlDbType.NVarChar,200),
					new SqlParameter("@BanHao", SqlDbType.NVarChar,200),
					new SqlParameter("@List_NOType", SqlDbType.NVarChar,200),
					new SqlParameter("@Posiont1", SqlDbType.NVarChar,200),
					new SqlParameter("@Posiont2", SqlDbType.NVarChar,200),
					new SqlParameter("@Product_Model", SqlDbType.NVarChar,200),
					new SqlParameter("@Serial_Number", SqlDbType.NVarChar,200),
					new SqlParameter("@Product_Weight", SqlDbType.Decimal,9),
					new SqlParameter("@Create_Time", SqlDbType.NVarChar,200),
					new SqlParameter("@Update_Time", SqlDbType.NVarChar,200),
					new SqlParameter("@Update_UserID", SqlDbType.VarChar,200),
					new SqlParameter("@RuKu_Time1", SqlDbType.NVarChar,200),
					new SqlParameter("@RuKu_Time2", SqlDbType.NVarChar,200),
					new SqlParameter("@BK01", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK02", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK03", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK04", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK05", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK06", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK07", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK08", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK09", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK10", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK11", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK12", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK13", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK14", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK15", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK16", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK17", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK18", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK19", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK20", SqlDbType.NVarChar,-1)};
			parameters[0].Value = model.PutList_NO;
			parameters[1].Value = model.OutList_NO;
			parameters[2].Value = model.PickList_NO;
			parameters[3].Value = model.BanHao;
			parameters[4].Value = model.List_NOType;
			parameters[5].Value = model.Posiont1;
			parameters[6].Value = model.Posiont2;
			parameters[7].Value = model.Product_Model;
			parameters[8].Value = model.Serial_Number;
			parameters[9].Value = model.Product_Weight;
			parameters[10].Value = model.Create_Time;
			parameters[11].Value = model.Update_Time;
			parameters[12].Value = model.Update_UserID;
			parameters[13].Value = model.RuKu_Time1;
			parameters[14].Value = model.RuKu_Time2;
			parameters[15].Value = model.BK01;
			parameters[16].Value = model.BK02;
			parameters[17].Value = model.BK03;
			parameters[18].Value = model.BK04;
			parameters[19].Value = model.BK05;
			parameters[20].Value = model.BK06;
			parameters[21].Value = model.BK07;
			parameters[22].Value = model.BK08;
			parameters[23].Value = model.BK09;
			parameters[24].Value = model.BK10;
			parameters[25].Value = model.BK11;
			parameters[26].Value = model.BK12;
			parameters[27].Value = model.BK13;
			parameters[28].Value = model.BK14;
			parameters[29].Value = model.BK15;
			parameters[30].Value = model.BK16;
			parameters[31].Value = model.BK17;
			parameters[32].Value = model.BK18;
			parameters[33].Value = model.BK19;
			parameters[34].Value = model.BK20;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(WMSAML.Warehouse.Model.T_PickStockPrepare model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_PickStockPrepare set ");
			strSql.Append("PutList_NO=@PutList_NO,");
			strSql.Append("OutList_NO=@OutList_NO,");
			strSql.Append("PickList_NO=@PickList_NO,");
			strSql.Append("BanHao=@BanHao,");
			strSql.Append("List_NOType=@List_NOType,");
			strSql.Append("Posiont1=@Posiont1,");
			strSql.Append("Posiont2=@Posiont2,");
			strSql.Append("Product_Model=@Product_Model,");
			strSql.Append("Serial_Number=@Serial_Number,");
			strSql.Append("Product_Weight=@Product_Weight,");
			strSql.Append("Create_Time=@Create_Time,");
			strSql.Append("Update_Time=@Update_Time,");
			strSql.Append("Update_UserID=@Update_UserID,");
			strSql.Append("RuKu_Time1=@RuKu_Time1,");
			strSql.Append("RuKu_Time2=@RuKu_Time2,");
			strSql.Append("BK01=@BK01,");
			strSql.Append("BK02=@BK02,");
			strSql.Append("BK03=@BK03,");
			strSql.Append("BK04=@BK04,");
			strSql.Append("BK05=@BK05,");
			strSql.Append("BK06=@BK06,");
			strSql.Append("BK07=@BK07,");
			strSql.Append("BK08=@BK08,");
			strSql.Append("BK09=@BK09,");
			strSql.Append("BK10=@BK10,");
			strSql.Append("BK11=@BK11,");
			strSql.Append("BK12=@BK12,");
			strSql.Append("BK13=@BK13,");
			strSql.Append("BK14=@BK14,");
			strSql.Append("BK15=@BK15,");
			strSql.Append("BK16=@BK16,");
			strSql.Append("BK17=@BK17,");
			strSql.Append("BK18=@BK18,");
			strSql.Append("BK19=@BK19,");
			strSql.Append("BK20=@BK20");
			strSql.Append(" where NID=@NID");
			SqlParameter[] parameters = {
					new SqlParameter("@PutList_NO", SqlDbType.NVarChar,200),
					new SqlParameter("@OutList_NO", SqlDbType.NVarChar,200),
					new SqlParameter("@PickList_NO", SqlDbType.NVarChar,200),
					new SqlParameter("@BanHao", SqlDbType.NVarChar,200),
					new SqlParameter("@List_NOType", SqlDbType.NVarChar,200),
					new SqlParameter("@Posiont1", SqlDbType.NVarChar,200),
					new SqlParameter("@Posiont2", SqlDbType.NVarChar,200),
					new SqlParameter("@Product_Model", SqlDbType.NVarChar,200),
					new SqlParameter("@Serial_Number", SqlDbType.NVarChar,200),
					new SqlParameter("@Product_Weight", SqlDbType.Decimal,9),
					new SqlParameter("@Create_Time", SqlDbType.NVarChar,200),
					new SqlParameter("@Update_Time", SqlDbType.NVarChar,200),
					new SqlParameter("@Update_UserID", SqlDbType.VarChar,200),
					new SqlParameter("@RuKu_Time1", SqlDbType.NVarChar,200),
					new SqlParameter("@RuKu_Time2", SqlDbType.NVarChar,200),
					new SqlParameter("@BK01", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK02", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK03", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK04", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK05", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK06", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK07", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK08", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK09", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK10", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK11", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK12", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK13", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK14", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK15", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK16", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK17", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK18", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK19", SqlDbType.NVarChar,-1),
					new SqlParameter("@BK20", SqlDbType.NVarChar,-1),
					new SqlParameter("@NID", SqlDbType.Int,4)};
			parameters[0].Value = model.PutList_NO;
			parameters[1].Value = model.OutList_NO;
			parameters[2].Value = model.PickList_NO;
			parameters[3].Value = model.BanHao;
			parameters[4].Value = model.List_NOType;
			parameters[5].Value = model.Posiont1;
			parameters[6].Value = model.Posiont2;
			parameters[7].Value = model.Product_Model;
			parameters[8].Value = model.Serial_Number;
			parameters[9].Value = model.Product_Weight;
			parameters[10].Value = model.Create_Time;
			parameters[11].Value = model.Update_Time;
			parameters[12].Value = model.Update_UserID;
			parameters[13].Value = model.RuKu_Time1;
			parameters[14].Value = model.RuKu_Time2;
			parameters[15].Value = model.BK01;
			parameters[16].Value = model.BK02;
			parameters[17].Value = model.BK03;
			parameters[18].Value = model.BK04;
			parameters[19].Value = model.BK05;
			parameters[20].Value = model.BK06;
			parameters[21].Value = model.BK07;
			parameters[22].Value = model.BK08;
			parameters[23].Value = model.BK09;
			parameters[24].Value = model.BK10;
			parameters[25].Value = model.BK11;
			parameters[26].Value = model.BK12;
			parameters[27].Value = model.BK13;
			parameters[28].Value = model.BK14;
			parameters[29].Value = model.BK15;
			parameters[30].Value = model.BK16;
			parameters[31].Value = model.BK17;
			parameters[32].Value = model.BK18;
			parameters[33].Value = model.BK19;
			parameters[34].Value = model.BK20;
			parameters[35].Value = model.NID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int NID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_PickStockPrepare ");
			strSql.Append(" where NID=@NID");
			SqlParameter[] parameters = {
					new SqlParameter("@NID", SqlDbType.Int,4)
			};
			parameters[0].Value = NID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string NIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_PickStockPrepare ");
			strSql.Append(" where NID in ("+NIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public WMSAML.Warehouse.Model.T_PickStockPrepare GetModel(int NID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 NID,PutList_NO,OutList_NO,PickList_NO,BanHao,List_NOType,Posiont1,Posiont2,Product_Model,Serial_Number,Product_Weight,Create_Time,Update_Time,Update_UserID,RuKu_Time1,RuKu_Time2,BK01,BK02,BK03,BK04,BK05,BK06,BK07,BK08,BK09,BK10,BK11,BK12,BK13,BK14,BK15,BK16,BK17,BK18,BK19,BK20 from T_PickStockPrepare ");
			strSql.Append(" where NID=@NID");
			SqlParameter[] parameters = {
					new SqlParameter("@NID", SqlDbType.Int,4)
			};
			parameters[0].Value = NID;

			WMSAML.Warehouse.Model.T_PickStockPrepare model=new WMSAML.Warehouse.Model.T_PickStockPrepare();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public WMSAML.Warehouse.Model.T_PickStockPrepare DataRowToModel(DataRow row)
		{
			WMSAML.Warehouse.Model.T_PickStockPrepare model=new WMSAML.Warehouse.Model.T_PickStockPrepare();
			if (row != null)
			{
				if(row["NID"]!=null && row["NID"].ToString()!="")
				{
					model.NID=int.Parse(row["NID"].ToString());
				}
				if(row["PutList_NO"]!=null)
				{
					model.PutList_NO=row["PutList_NO"].ToString();
				}
				if(row["OutList_NO"]!=null)
				{
					model.OutList_NO=row["OutList_NO"].ToString();
				}
				if(row["PickList_NO"]!=null)
				{
					model.PickList_NO=row["PickList_NO"].ToString();
				}
				if(row["BanHao"]!=null)
				{
					model.BanHao=row["BanHao"].ToString();
				}
				if(row["List_NOType"]!=null)
				{
					model.List_NOType=row["List_NOType"].ToString();
				}
				if(row["Posiont1"]!=null)
				{
					model.Posiont1=row["Posiont1"].ToString();
				}
				if(row["Posiont2"]!=null)
				{
					model.Posiont2=row["Posiont2"].ToString();
				}
				if(row["Product_Model"]!=null)
				{
					model.Product_Model=row["Product_Model"].ToString();
				}
				if(row["Serial_Number"]!=null)
				{
					model.Serial_Number=row["Serial_Number"].ToString();
				}
				if(row["Product_Weight"]!=null && row["Product_Weight"].ToString()!="")
				{
					model.Product_Weight=decimal.Parse(row["Product_Weight"].ToString());
				}
				if(row["Create_Time"]!=null)
				{
					model.Create_Time=row["Create_Time"].ToString();
				}
				if(row["Update_Time"]!=null)
				{
					model.Update_Time=row["Update_Time"].ToString();
				}
				if(row["Update_UserID"]!=null)
				{
					model.Update_UserID=row["Update_UserID"].ToString();
				}
				if(row["RuKu_Time1"]!=null)
				{
					model.RuKu_Time1=row["RuKu_Time1"].ToString();
				}
				if(row["RuKu_Time2"]!=null)
				{
					model.RuKu_Time2=row["RuKu_Time2"].ToString();
				}
				if(row["BK01"]!=null)
				{
					model.BK01=row["BK01"].ToString();
				}
				if(row["BK02"]!=null)
				{
					model.BK02=row["BK02"].ToString();
				}
				if(row["BK03"]!=null)
				{
					model.BK03=row["BK03"].ToString();
				}
				if(row["BK04"]!=null)
				{
					model.BK04=row["BK04"].ToString();
				}
				if(row["BK05"]!=null)
				{
					model.BK05=row["BK05"].ToString();
				}
				if(row["BK06"]!=null)
				{
					model.BK06=row["BK06"].ToString();
				}
				if(row["BK07"]!=null)
				{
					model.BK07=row["BK07"].ToString();
				}
				if(row["BK08"]!=null)
				{
					model.BK08=row["BK08"].ToString();
				}
				if(row["BK09"]!=null)
				{
					model.BK09=row["BK09"].ToString();
				}
				if(row["BK10"]!=null)
				{
					model.BK10=row["BK10"].ToString();
				}
				if(row["BK11"]!=null)
				{
					model.BK11=row["BK11"].ToString();
				}
				if(row["BK12"]!=null)
				{
					model.BK12=row["BK12"].ToString();
				}
				if(row["BK13"]!=null)
				{
					model.BK13=row["BK13"].ToString();
				}
				if(row["BK14"]!=null)
				{
					model.BK14=row["BK14"].ToString();
				}
				if(row["BK15"]!=null)
				{
					model.BK15=row["BK15"].ToString();
				}
				if(row["BK16"]!=null)
				{
					model.BK16=row["BK16"].ToString();
				}
				if(row["BK17"]!=null)
				{
					model.BK17=row["BK17"].ToString();
				}
				if(row["BK18"]!=null)
				{
					model.BK18=row["BK18"].ToString();
				}
				if(row["BK19"]!=null)
				{
					model.BK19=row["BK19"].ToString();
				}
				if(row["BK20"]!=null)
				{
					model.BK20=row["BK20"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select NID,PutList_NO,OutList_NO,PickList_NO,BanHao,List_NOType,Posiont1,Posiont2,Product_Model,Serial_Number,Product_Weight,Create_Time,Update_Time,Update_UserID,RuKu_Time1,RuKu_Time2,BK01,BK02,BK03,BK04,BK05,BK06,BK07,BK08,BK09,BK10,BK11,BK12,BK13,BK14,BK15,BK16,BK17,BK18,BK19,BK20 ");
			strSql.Append(" FROM T_PickStockPrepare ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" NID,PutList_NO,OutList_NO,PickList_NO,BanHao,List_NOType,Posiont1,Posiont2,Product_Model,Serial_Number,Product_Weight,Create_Time,Update_Time,Update_UserID,RuKu_Time1,RuKu_Time2,BK01,BK02,BK03,BK04,BK05,BK06,BK07,BK08,BK09,BK10,BK11,BK12,BK13,BK14,BK15,BK16,BK17,BK18,BK19,BK20 ");
			strSql.Append(" FROM T_PickStockPrepare ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_PickStockPrepare ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.NID desc");
			}
			strSql.Append(")AS Row, T.*  from T_PickStockPrepare T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_PickStockPrepare";
			parameters[1].Value = "NID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

